'use strict'

class upload {

  constructor () {
    //param默认就是/:id，若要改变路由，则可以设置此属性，比如设置为/:name
    //this.param = '/:id'
  }

  //以下方法，若不需要，要去掉，避免无意义的路由。

  //创建资源
  //对应路由 POST /square
  async post (c) {
    let u=c.box.user;
    let posts_time=Date.now();
    let posts_id=c.helper.makeId();
    let sqltext = `INSERT INTO square(open_id,posts_text,posts_image,posts_time,posts_id,love) VALUES($1,$2,$3,$4,$5,$6)`;
    let r = await c.service.psql.query(sqltext,[u.openid,c.body.text,c.body.img_url,posts_time,posts_id,false]);
    c.send(r.rows);
    
  }
  //获取列表
  async list (c) {
    let ret = await c.service.psql.query(`select * from square`)
    //等效于c.res.body=ret.rows
    c.send(ret.rows)
  }



}

module.exports = upload
